<?php
header('Content-Type:text/html;charset=utf-8');
?>
<html>
  <head>
    <title>点餐</title>
    <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css">
    <script src="js/jquery-1.11.3.js"></script>
    <script src="js/bootstrap.js"></script>
  </head>
  <body>
    <?php include 'nav.php' ?>
    <div class="container">
      <div class="col-xs-2">
        <div class="input-group">
          <input type="text" class="form-control" placeholder="桌号" aria-describedby="basic-btn">
          <div class="input-group-btn" id="basic-btn">
            <button type="submit" class="btn btn-default">
            <span class="glyphicon glyphicon-search" style="height:20px">
            </span>
            </button>
          </div>
        </div>
        <div style="margin-top:20px" align="center">
        <?php
			$PDO=new PDO('mysql:dbname=diancan;charset=UTF8;','root');
			$room=$PDO->prepare('select * from canzhuo');
			$room->execute(array());
			$AAA=$room->fetchAll(PDO::FETCH_NAMED);
			foreach ($AAA as $key => $value) 
				{?>
				<a class="list-group-item" href="/diancan.php?zzid=<?php echo $value['ID'] ?>">
				<?php
				echo $value['name'];
				?>
				</a>
				<?php
			}
		?>
        </div>
       </div> 

		<div class="col-xs-10">     		
				<div class="panel panel-primary">
					<div class="panel-heading" role="tab" id="headingOne">
						<div class="row">
			              <div class="col-xs-10">

			              	<a role="button" style="color:#fff;width: 100%; display: block;" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne">
						        <span class="glyphicon glyphicon-ok"></span>
								
								<?php
								$aaa="0";
								$a="0";
								@$a=$_GET['zzid'];
								
								$se=$PDO->prepare('select * from canzhuo where id=:abc');
								$se->execute(array('abc'=>$a)) ;
								$FFF=$se->fetchAll(PDO::FETCH_NAMED); 
				              	if ($FFF) {
				              	    echo $FFF[0]['name'];
				              	    $aaa="1";
			              	    }else{
									echo "尚未选择餐桌";									
			              	    }  ?>

        					</a>
		                  </div>
			              <div class="col-xs-2">
			                <a href="/jz.php?czid=<?php echo $value['ID'] ?>" class="btn btn-success">结账
			                
			                元 </a>
			              </div>
			         	</div>

					</div>
					<div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne">
					  <div class="panel-body">
					  	<div class="row">
			                	<?php
								$MM="0";
								@$b=$_GET['cpdid'];
								$dd=$PDO->prepare('select * from order1');
								$dd->execute() ;
								$DD=$dd->fetchAll(PDO::FETCH_NAMED);
								foreach ($DD as $o => $ord) {
										if ($ord['canzhuoID']==$a) {
											$MM="1";	
											break;
										}
									}
								
								if($b!=0){
									if (empty($DD)) {
									$czdd=$PDO->prepare('insert into order1(canzhuoID) values(:aa)');
									$czdd->execute(array('aa'=>$a));
									$ddd=$PDO->prepare('select * from order1 where canzhuoID=:aa');
									$ddd->execute(array('aa'=>$a)) ;
									$DDD=$ddd->fetchAll(PDO::FETCH_NAMED);
									$QWE=$DDD[0]['ID'];
									$chdd=$PDO->prepare('insert into VTorder1(VTID,order1ID) values(:aa,:bb)');
									$chdd->execute(array('aa'=>$b,'bb'=>$QWE));
									}elseif ($MM==1){
										$ddd=$PDO->prepare('select * from order1 where canzhuoID=:aa');
										$ddd->execute(array('aa'=>$a)) ;
										$DDD=$ddd->fetchAll(PDO::FETCH_NAMED);
										$QWE=$DDD[0]['ID'];
										$chdd=$PDO->prepare('insert into VTorder1(VTID,order1ID) values(:aa,:bb)');
										$chdd->execute(array('aa'=>$b,'bb'=>$QWE));
									}else{									
										$czdd=$PDO->prepare('insert into order1(canzhuoID) values(:aa)');
										$czdd->execute(array('aa'=>$a));
										$ddd=$PDO->prepare('select * from order1 where canzhuoID=:aa');
										$ddd->execute(array('aa'=>$a)) ;
										$DDD=$ddd->fetchAll(PDO::FETCH_NAMED);
										$QWE=$DDD[0]['ID'];
										$chdd=$PDO->prepare('insert into VTorder1(VTID,order1ID) values(:aa,:bb)');
										$chdd->execute(array('aa'=>$b,'bb'=>$QWE));
									}
								}

								

								
								$sel=$PDO->prepare('select * from order1,canzhuo,VTbiao,VTorder1 where VTorder1.order1ID=order1.ID and VTorder1.VTID=VTbiao.ID and order1.canzhuoID=canzhuo.ID and canzhuo.ID=:czid');
								$sel->execute(array('czid'=>$a));
								$ZZ=$sel->fetchAll(PDO::FETCH_NAMED);
								if ($ZZ) {
									if ($aaa==1) { 
										foreach($ZZ as $X=>$ZZB){ ?>
											<div class="col-xs-2">
								                <div class="thumbnail">
								                  <img style="width:100px;height:100px" src="<?php echo $ZZB['picture']; ?>"/>
								                  <div class="caption text-center"><?php echo $ZZB['name'][1],$ZZB['unitPrice'][0]; ?></div>
												  <a href="/sdcp.php?cdid=<?php echo $ZZB['ID'][0]; ?>">
													  <div class="caption text-center" style="color:blue">取消</div>
												  </a>
								                </div>
								            </div>
										<?php }
									}else{ ?>
											<div class="alert alert-warning alert-dismissible" role="alert">
											  <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
											  <strong>错误</strong> 未选择餐桌.
											</div>
									<?php } 	
								}?>
			            </div>
					  </div>
					</div>
				</div>

        <div class="panel panel-primary" style="margin-top:20px">
	      <div class="panel-heading">
	        <div class="row">
	          <div class="col-xs-8">
	            <span class="glyphicon glyphicon-th-list"></span>
	            可选菜品 </div>
	          <div class="col-xs-4">
	            <div class="input-group">
	              <input type="text" placeholder="菜名" class="form-control">
	              <div class="input-group-btn">
	                <select class="btn btn-default" style="height:34px">
						<option>全部</option>
						<?php
							$PDO=new PDO('mysql:dbname=diancan;charset=UTF8;','root');
							$cai=$PDO->prepare('select * from VTtype');
							$cai->execute(array());
							$AA=$cai->fetchAll(PDO::FETCH_NAMED);
							foreach ($AA as $AB => $AC) 
							{?>
								<option>
								<?php
								echo $AC['typeName'];
								?>
								</option>
								<?php
							}
						?>
	                </select>
	                <button type="submit" class="btn btn-default">
	                <span class="glyphicon glyphicon-search" style="height:20px">
	                </span>
	                </button>
	              </div>
	            </div>
	          </div>
	        </div>
	      </div>
	      <div class="panel-body">
	      	<div class="row">
	      		<?php 
	      		$cc=$PDO->prepare('select * from VTbiao');
				$cc->execute(array());
				$BA=$cc->fetchAll(PDO::FETCH_NAMED);
	      		foreach ($BA as $BB => $BC) { ?>

	      		<div class="col-xs-2">
	                <div class="thumbnail">

	                  <a href="/diancan.php?cpdid=<?php echo $BC['ID']; ?>&zzid=<?php echo $a ?>">
	                  	<img style="width:100px;height:100px" src="<?php echo $BC['picture']; ?>"/>
	                  
					  
						  <div class="caption text-center" style="color:blue"><?php echo $BC['name'].$BC['unitPrice']; ?></div>
					  </a>
	                </div>
	             </div>
	             <?php } ?>
	      		
	      	</div>
	        
	      </div>
	    </div>
	    </div>
	    
      </div>
 
  </body>
</html>